﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class KnockOutController : Controller
    {
        [HttpPost]
        public ActionResult Postedata(Person person)
        {
            return View(); 
        }


        public ActionResult PostingJson()
        {
            return View();
        }

        public ActionResult ShowingJsonResultInTextArea()
        {
            return View();
        } 

        public ActionResult AddNewRowForInfo()
        {
            return View();
        } 

        public ActionResult RemovePhoneFunctionlity()
        {
            return View();
        } 

        public ActionResult AddFunctionLity()
        {
            return View();
        }
        public ActionResult RemoveFunctionlity()
        {
            return View();
        }

        public ActionResult AddtemplateUsingMVCBackEnd()
        {
            return View();
        }




        [HttpPost]
        public ActionResult LoadContacts()
        {
            //{ firstName: "Avinash", lastName: "Tiwari", phones: [
            //            { type: "Mobile", number: "99999999999999999" },
            //            { type: "Home", number: "999999999999999999"}]
            //        },
            //        { firstName: "Avinash1", lastName: "Tiwari1", phones: [
            //            { type: "Mobile", number: "0000000000000" },
            //            { type: "Home", number: "0000000000000"}]
            //        }

            var model = new List<Person>
                            {
                                new Person
                                    {
                                        firstName = "Avinash",
                                        lastName = "Tiwari",
                                        phones = new List<Phone>
                                                     {
                                                         new Phone
                                                             {
                                                                 type = "Mobile", 
                                                                 number = "99999999999999999"
                                                             },
                                                             new Phone
                                                             {
                                                                 type = "Home", 
                                                                 number = "999999999999999999"
                                                             }
                                                     }
                                    },
                                    new Person
                                    {
                                        firstName = "Avinash1",
                                        lastName = "Tiwari1",
                                        phones = new List<Phone>
                                                     {
                                                         new Phone
                                                             {
                                                                 type = "Mobile", 
                                                                 number = "0000000000000"
                                                             },
                                                             new Phone
                                                             {
                                                                 type = "Home", 
                                                                 number = "99999999999999999"
                                                             }
                                                     }
                                    }
                            };
            return Json(model,JsonRequestBehavior.AllowGet);
        }
        //
        // GET: /KnockOut/

        public JsonResult AutoCompleteJson()
        {
            products product = new products();
            product.name = "1948 Porsche 356-A Roadster";
            product.price = 1;

            List<namevaluCollectionAutoComplete> myNameValueColl = new List<namevaluCollectionAutoComplete>();
            myNameValueColl = null;
            product.product = myNameValueColl;

            return Json(product, JsonRequestBehavior.AllowGet);
        }


        public ActionResult AutoCompleteFromBackEnd()
        {
            return View();
        }

        public ActionResult AutoCompleteWithJavascriptFile()
        {
            return View();
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult DependencyKnockOut()
        {
            return View();
        }

        public ActionResult ComplexDependency()
        {
            return View();
        }

        public ActionResult Templateing()
        {
            return View();
        }

        public ActionResult TemplatWithButton()
        {
            return View();
        }

        public ActionResult TemplatWithCaching()
        {
            return View();
        }

        public ActionResult CRUD()
        {
            return View();
        }

        public ActionResult ServerCall()
        {
            return View();
        }

        public JsonResult Save(Person person)
        {
            var message = string.Format("Saved {0} {1}", person.firstName, person.lastName);
          //  message += string.Format(" with {0} friends", person.friends.Count);
         //   message += string.Format(" ({0} on Twitter) ", person.friends.Where(x => x.isOnTwitter).Count());
            return Json(new { message });
        }

        public ActionResult FillList()
        {
            return View();
        }

        public JsonResult FillList1(string q)
        {
           
            List<string> texts = new List<string>();

          texts.Add("asp");

          texts.Add("mvc");

           texts.Add("microsoft");

           texts.Add("sql server");

           texts.Add("jQuery");

           texts.Add("ajax");
       
    

           // Select the texts that match the query, and get the 

           // number or texts specified by the limit.

           var retValue = texts

               .Where(x => x.StartsWith(q))

              .OrderBy(x => x)

               .Take(10)

               .Select(r => new { text = r });

    

          // Return the result set as JSON

           return Json(retValue,JsonRequestBehavior.AllowGet);
        }

        public ActionResult OptionBinding()
        {
            /// this is Inisde The live Example of KnockOut Js
            return View();
        }

        public ActionResult OptionBindingSample2()
        {
            /// this is Inisde The live Example of KnockOut Js
            return View();
        }

        public ActionResult TwitterSampleFromLiveExample()
        {
            /// this is Inisde The live Example of KnockOut Js
            return View();
        }

        public ActionResult SimpleTwitterList()
        {
            return View();
        }
    }
}
